
//3105.最长的严格递增或递减子数组
class Solution {
public:
    int longestMonotonicSubarray(vector<int>& nums) {
        //简单的分组循环
        int n=nums.size();
        int i=0,ret=1;
        while(i<n-1)
        {
            int start=i++;
            int flag=nums[i]-nums[start];  //记录是递增还是递减的
            while(flag<0&&i<n-1&&nums[i]>nums[i+1]) i++;
            while(flag>0&&i<n-1&&nums[i]<nums[i+1]) i++;

            if(flag!=0) ret=max(ret,i-start+1);   //相等不需要进行更新
        }
        return ret;
    }
};